
public class DeadLock {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		final Object resource1 = new Object();
		final Object resource2 = new Object();
		
		Thread thread1 = new Thread(){
			public void run() {
				synchronized(resource1) {
					System.out.println("Thead1 lock res1");
					try {
						Thread.sleep(50);
					} catch(InterruptedException ie) {
						
					}
					
					synchronized(resource2) {
						System.out.println("Thead1 lock res2");
					}
				}				
			}
		};
		
		Thread thread2 = new Thread(){
			public void run() {
				synchronized(resource2) {
					System.out.println("Thead2 lock res2");
					try {
						Thread.sleep(50);
					} catch(InterruptedException ie) {
						
					}
					
					synchronized(resource1) {
						System.out.println("Thead2 lock res1");
					}
				}				
			}
		};
		
		thread1.start();
		thread2.start();

	}

}
